package com.example.gw_back_end.controller;

import com.example.gw_back_end.domain.Result;
import com.example.gw_back_end.domain.entities.GameDownloadLink;
import com.example.gw_back_end.service.GameDownloadLinkService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("game_download_link")
public class GameDownloadLinkController {

    private final GameDownloadLinkService gameDownloadLinkService;
    public GameDownloadLinkController(GameDownloadLinkService gameDownloadLinkService) {
        this.gameDownloadLinkService = gameDownloadLinkService;
    }

    // 新增游戏下载地址
    @PostMapping("add_game_download_link")
    public Result addGameDownloadLink(GameDownloadLink gameDownloadLink) {
        if (gameDownloadLinkService.save(gameDownloadLink)) {
            return Result.success();
        } else {
            return Result.error("新增游戏下载地址失败,请稍后重试！");
        }
    }

    // 获取游戏下载地址
    @GetMapping("get_game_download_link")
    public Result getGameDownloadLinkByGameId(String gameId) {
        return Result.success(gameDownloadLinkService.getGameDownloadLink(gameId));
    }

    // 更新游戏下载地址
    @PutMapping("update_game_download_link")
    public Result updateGameDownloadLink(GameDownloadLink gameDownloadLink) {
        if (gameDownloadLinkService.updateGameDownloadLink(gameDownloadLink)) {
            return Result.success();
        } else {
            return Result.error("更新游戏下载地址失败,请稍后重试！");
        }
    }
}
